﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Internal;
using System.Collections.Generic;

namespace CADTool.Jig
{
    public class JigDBTextZDBH : DrawJig
    {
        private Point3d basePoint;
        private DBText txt;
        private DBText txt1;
        private Circle circle;
        private Line line;
        public JigDBTextZDBH(DBText txt, DBText txt1, Circle circle, Line line)
        {
            this.txt = txt;
            this.txt1 = txt1;
            this.line = line;
            this.circle = new Circle()
            {
                Radius = 6,
                ColorIndex = 1,
            };          
        }
        public List<Entity> GetEntity()
        {
            return new List<Entity> { txt, txt1, circle, line };
        }
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            PromptPointResult psr = prompts.AcquirePoint();
            if (psr.Status == PromptStatus.OK)
            {
                Point3d temp = psr.Value;
                if (temp != basePoint)
                {
                    basePoint = temp;
                    txt.AlignmentPoint = basePoint + new Vector3d(0, -1.0, 0);
                    txt.ColorIndex = 1;
                    txt.SetDatabaseDefaults();
                    txt.AdjustAlignment(Z.db);
                    txt1.AlignmentPoint= basePoint + new Vector3d(0, -0.1, 0);
                    txt1.ColorIndex = 1;               
                    txt1.SetDatabaseDefaults();
                    txt1.AdjustAlignment(Z.db);
                    circle.Center = basePoint;
                    line.StartPoint = basePoint + new Vector3d(6, 0, 0);
                    line.EndPoint = basePoint + new Vector3d(-6, 0, 0);
                    line.ColorIndex = 1;
                    if (txt.Height == 0)
                    {
                        txt.Height = 4;
                    }
                    return SamplerStatus.NoChange;
                }
            }
            return SamplerStatus.NoChange;
        }

        protected override bool WorldDraw(WorldDraw draw)
        {
            draw.Geometry.Draw(txt);
            draw.Geometry.Draw(txt1);
            draw.Geometry.Draw(circle);
            draw.Geometry.Draw(line);
            return true;
        }
    }
}
